﻿using Abp.Application.Services.Dto;
using FwProject.Comm.ExcelUtil;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using X.PagedList;

namespace FwProject.Distribution.Dto
{
    public class TotalSummaryReceivableDto
    {
        public IPagedList<SummaryReceivableOutputDto> PageList { get; set; }

        /// <summary>
        /// 总配送金额
        /// </summary>
        public decimal TotalDistributionPrice { get; set; }

        /// <summary>
        /// 总应收金额
        /// </summary>
        public decimal TotalSummaryPrice { get; set; }

        /// <summary>
        /// 总优惠金额
        /// </summary>
        public decimal TotalDiscountPrice { get; set; }

        /// <summary>
        /// 总实际收款
        /// </summary>
        public decimal TotalReceivedPrice { get; set; }

        /// <summary>
        /// 总未收款
        /// </summary>
        public decimal TotalNotActualprice { get { return TotalDistributionPrice - TotalDiscountPrice - TotalReceivedPrice - TotalUsePrePayment; } }

        /// <summary>
        /// 总预收金额
        /// </summary>
        public decimal TotalUsePrePayment { get; set; }


        public int TotalDistributionCount { get; set; }

        public int TotalRecoveryCount { get; set; }

        public int TotalGiveCount { get; set; }

        public int TotalExChangedCount { get; set; }
    }

    [DisplayName(displayName:"应收汇总")]
    public class SummaryReceivableOutputDto : EntityDto<Guid>
    {
        /// <summary>
        /// 餐厅名称
        /// </summary>
        [DisplayName(displayName:"餐厅名称")]
        [ExcelDateMember(IsMerged =true)]
        public string RestaurantName { get; set; }

        /// <summary>
        /// 配送金额
        /// </summary>
        [DisplayName(displayName:"配送金额")]
        [ExcelDateMember(IsMerged =true,IsSum =true)]
        public decimal DistributionPrice { get; set; }
        /// <summary>
        /// 收据金额
        /// </summary>

        public Guid SettlementId { get; set; }

        /// <summary>
        /// 总优惠
        /// </summary>
        [DisplayName(displayName: "总优惠")]
        [ExcelDateMember(IsMerged =true,IsSum =true)]
        public decimal TotalDiscount { get; set; }

        /// <summary>
        /// 折扣率
        /// </summary>
        [DisplayName(displayName: "折扣率")]
        [ExcelDateMember(IsMerged = true)]
        public string DiscountRate { get { return DistributionPrice==0 ? "0.00%" : (Convert.ToDouble(TotalDiscount) / Convert.ToDouble(DistributionPrice)).ToString("0.00%"); } }

        /// <summary>
        /// 应收金额
        /// </summary>
        [DisplayName(displayName: "应收金额")]
        [ExcelDateMember(IsMerged =true,IsSum =true)]
        public decimal TotalPrice { get { return DistributionPrice - TotalDiscount; } }

        /// <summary>
        /// 实际金额
        /// </summary>
        public decimal Actualprice { get; set; }
        /// <summary>
        /// 未收金额
        /// </summary>
        [DisplayName(displayName: "未收金额")]
        [ExcelDateMember(IsMerged =true,IsSum =true)]
        public decimal NotActualprice { get { return DistributionPrice - TotalDiscount - ReceivedPrice - UsePrePayment; } }

        /// <summary>
        /// 预收金额
        /// </summary>
        [DisplayName(displayName: "预收金额")]
        [ExcelDateMember(IsMerged = true, IsSum = true)]
        public decimal UsePrePayment { get; set; }
        /// <summary>
        /// 已收金额
        /// </summary>
        [DisplayName(displayName: "已收金额")]
        [ExcelDateMember(IsMerged = true, IsSum = true)]
        public decimal ReceivedPrice { get; set; }

        /// <summary>
        /// 开单日期
        /// </summary>
        public DateTime CreationTime { get; set; }

        [ExcelDateMember(IsClass =true, IsMultiRow = true)]
        public List<SummaryDistribution> SummaryDistributions { get; set; }

    }

    public class SummaryDistribution
    {
        /// <summary>
        /// 型号名称
        /// </summary>
        [DisplayName(displayName:"货品名称")]
        [ExcelDateMember]
        public string TypeNumberName { get; set; }

        /// <summary>
        /// 配送箱数
        /// </summary>
        [DisplayName(displayName: "配送箱数")]
        [ExcelDateMember(IsSum = true)]
        public int DistributionCount { get; set; }

        /// <summary>
        /// 回收数量
        /// </summary>
        [DisplayName(displayName: "回收数量")]
        [ExcelDateMember(IsSum = true)]
        public int RecoveryCount { get; set; }

        /// <summary>
        /// 赠送数量
        /// </summary>
        [DisplayName(displayName: "赠送数量")]
        [ExcelDateMember(IsSum = true)]
        public int GiveCount { get; set; }

        /// <summary>
        /// 换货数量
        /// </summary>
        [DisplayName(displayName: "换货数量")]
        [ExcelDateMember(IsMultiRow = true, IsSum = true)]
        public int ExchangegoodsCount { get; set; }
    }


}
